package huawei.dfs;

import treenode.TreeNode;

/**
 * https://www.nowcoder.com/practice/508378c0823c423baa723ce448cbfd0c?tpId=196&rp=1&ru=%2Fexam%2Foj&qru=%2Fexam%2Foj&sourceUrl=%2Fexam%2Foj%3Ftab%3D%25E7%25AE%2597%25E6%25B3%2595%25E7%25AF%2587%26topicId%3D196%26page%3D1%26search%3D13&difficulty=&judgeStatus=&tags=&title=9&gioEnter=menu
 */
public class NC9 {
    public static boolean hasPathSum(TreeNode root,int sum){
        if(root==null){
            return false;
        }
        if(root.left==null&&root.right==null){
            return sum==root.val;
        }
        return hasPathSum(root.left,sum-root.val)||hasPathSum(root.right,sum-root.val);
    }

}
